import "../css/tableOutput-DWvU-FoH.css";
import { _ as be, a as fe, b as he, c as ye, d as we, e as ke, f as Ne, g as xe, h as Te, i as Ve, j as Ce, k as Ye, l as $e, m as De, n as Fe, o as Ie, p as Le, q as Pe, r as Oe, s as je, t as qe, u as Ee, v as Ue, w as ze, x as Se, y as Be, z as Me, A as Re, B as Ge, C as Ae, D as He, E as Je, F as Ke, G as Qe, H as We, I as Xe, J as Ze, K as et, L as tt, M as at, N as it, O as nt, P as lt, Q as st, R as ot, S as _t, T as rt, U as ct, V as pt, W as ut, X as dt, Y as gt, Z as vt, $ as mt, a0 as bt, a1 as ft, a2 as ht, a3 as yt, a4 as wt, a5 as kt, a6 as Nt, a7 as xt, a8 as Tt, a9 as Vt, aa as Ct, ab as Yt } from "./table.DtQlpGd_.js";
import { defineComponent as ee, ref as ie, reactive as X, h as D, toRefs as $t, watch as de, openBlock as w, createElementBlock as j, createElementVNode as M, createVNode as k, unref as a, createBlock as te, withCtx as F, createTextVNode as ne, toDisplayString as Dt, createCommentVNode as Ft, computed as Z, onMounted as It, Fragment as oe, renderList as _e, withModifiers as re } from "vue";
import { bL as ce, b as le, b3 as Lt, b_ as Pt, a9 as Ot, u as jt, g as h, B as pe, C as B, j as se, k as qt, _ as ae, t as Et, m as T, a as ue, f as K } from "./vendor.CF2kwqqq.js";
import { U as Ut } from "./useApi.C6EqDb1N.js";
const zt = {
  "w-full": "",
  "overflow-auto": ""
}, St = {
  flex: "",
  "gap-2em": "",
  "h-32": "",
  "flex-wrap": ""
}, Bt = /* @__PURE__ */ ee({
  __name: "data-table-new",
  props: {
    serverId: { default: "" },
    schemaIds: { default: () => [] },
    groups: { default: () => [] },
    testConnect: {}
  },
  emits: ["update:serverId", "update:schemaIds", "put:server", "put:schema", "change"],
  setup(C, { emit: R }) {
    const q = /* @__PURE__ */ Object.assign({ "./icon/airbyte.png": be, "./icon/airflow.png": fe, "./icon/amazon-s3.png": he, "./icon/amundsen.png": ye, "./icon/athena.png": we, "./icon/atlas.png": ke, "./icon/azuresql.png": Ne, "./icon/bigquery.png": xe, "./icon/clickhouse.png": Te, "./icon/databrick.png": Ve, "./icon/dbt.png": Ce, "./icon/delta-lake.png": Ye, "./icon/domo.png": $e, "./icon/doris.png": De, "./icon/druid.png": Fe, "./icon/dynamodb.png": Ie, "./icon/glue.png": Le, "./icon/googleCloudService.png": Pe, "./icon/hive.png": Oe, "./icon/ibmdb2.png": je, "./icon/iceberg.png": qe, "./icon/impala.png": Ee, "./icon/kafka.png": Ue, "./icon/kinesis.png": ze, "./icon/looker.png": Se, "./icon/mariadb.png": Be, "./icon/metabase.png": Me, "./icon/mlflow.png": Re, "./icon/mode.png": Ge, "./icon/mongodb.png": Ae, "./icon/mssql.png": He, "./icon/mysql.png": Je, "./icon/oracle.png": Ke, "./icon/pinot.png": Qe, "./icon/postgres.png": We, "./icon/power-bi.png": Xe, "./icon/presto.png": Ze, "./icon/qliksense.png": et, "./icon/quicksight.png": tt, "./icon/redash.png": at, "./icon/redpanda.png": it, "./icon/redshift.png": nt, "./icon/sagemaker.png": lt, "./icon/salesforce.png": st, "./icon/saphana.png": ot, "./icon/singlestore.png": _t, "./icon/snowflakes.png": rt, "./icon/sqlalchemy.png": ct, "./icon/sqlite.png": pt, "./icon/superset.png": ut, "./icon/tableau.png": dt, "./icon/trino.png": gt, "./icon/vertica.png": vt }), E = /* @__PURE__ */ Object.assign({ "./svg/dakaishujukulianjie.svg": mt, "./svg/database.svg": bt, "./svg/field.svg": ft, "./svg/icon_clickhouse.svg": ht, "./svg/liebiaoziduanguanli.svg": yt, "./svg/mongodb.svg": wt, "./svg/mysql.svg": kt, "./svg/oracle.svg": Nt, "./svg/postgresql.svg": xt, "./svg/schema.svg": Tt, "./svg/server.svg": Vt, "./svg/shujuku.svg": Ct, "./svg/table.svg": Yt }), G = C, { serverId: U, schemaIds: A, groups: H, testConnect: I } = G, L = R, P = new Ut(), l = P.getNextDataLinkList.bind(P), s = (r, c) => {
      let m = "";
      const N = r.toLowerCase();
      if (c && c == "group") {
        const b = (Object.keys(q) || []).find((Y) => Y.includes(N));
        b && (m = q[b].default);
      } else {
        const b = (Object.keys(E) || []).find((Y) => Y.includes(N));
        b && (m = E[b].default);
      }
      return m;
    }, v = ie(!1), u = X({}), d = ie(), y = (r) => {
      d.value = r;
    }, z = async () => {
      if (I) {
        v.value = !0;
        try {
          console.log("testConnect....", e);
          const r = await I(d.value, e);
          u[d.value.id] = r;
        } catch (r) {
          console.error(r);
        }
        v.value = !1;
      }
    }, O = ee({
      props: ["id", "groups"],
      emits: ["up:server", "up:id"],
      setup(r, c) {
        const { id: m = "", groups: N } = r, g = { label: "label", leaf: "isLeaf", children: "children", value: "value", emitPath: !1 }, b = X([]), Y = async () => {
          b.length = 0;
          const p = await l(), $ = Ot(p.data, "serviceType"), n = Object.keys($).filter((t) => N.length > 0 ? N.includes(t) : !0).map((t) => ({ label: t, value: t, data: t, icon: t, type: "group", children: $[t].map((o) => ({ group: t, label: o.displayName || o.name, type: p.type, value: o.id, data: o, isLeaf: !0 })) }));
          if (b.push(...n), m) {
            const t = p.data.find((o) => o.id == m);
            c.emit("up:server", t);
          }
        };
        let Q = m;
        const W = (p) => {
          if (p.isLeaf) {
            const $ = p.value, J = p.data;
            Q = $, c.emit("up:id", $), c.emit("up:server", J), console.log("Server --------------", $, J);
          }
        };
        return Y(), () => D(ce, { modelValue: Q, options: b, props: { ...g } }, {
          default: ({ data: p }) => D("div", { style: "display:flex;align-items:center;gap:.5em;", onClick: () => W(p) }, [
            D("img", { style: "height:1em;max-height:1em;", src: s(p.type == "group" ? p.label : p.type, p.type), title: `${p.type} - ${p.label}` }),
            D("span", p.label)
          ])
        });
      }
    });
    let e, i = "", _ = [];
    const f = (r, c = []) => {
      i = r ? `select * from ${r}` : "", _ = c, r && me();
    }, ge = (r) => {
      console.log("..234234......", r), e = r;
    }, ve = ee({
      props: ["ids", "server"],
      emits: ["up:ids", "up:name", "up:database"],
      setup(r, c) {
        const { server: m } = $t(r), { ids: N = [] } = r, g = X([...N]), b = X([]), Y = (n = []) => {
          b.length = 0, b.push(...n);
        }, Q = (n) => n.data.map((t) => ({ label: t.displayName || t.name, type: n.type, value: t.id, data: t, isLeaf: t.columns != null })), W = async (n) => {
          var t, o;
          if (n) {
            const x = await l(n);
            Y(Q(x));
            const S = g.length > 0 ? (t = x.data) == null ? void 0 : t.find((V) => V.id == g[0]) : (o = x.data) == null ? void 0 : o[0];
            c.emit("up:database", S);
          } else
            Y();
        }, p = { label: "label", leaf: "isLeaf", children: "children", value: "value", lazy: !0, emitPath: !0, multiple: !1, checkStrictly: !1 }, $ = async (n, t) => {
          const o = n.data;
          let x = [];
          if (o && o.children)
            x = o.children;
          else if (o && o.data && o.value) {
            const S = await l(o.data);
            x = S.data.map((V) => ({ label: V.displayName || V.name, type: S.type, value: V.id, parent: o, data: V, isLeaf: V.columns != null }));
          }
          t(x);
        }, J = (n) => {
          if (!n.isLeaf)
            return;
          let t = n;
          const o = [n.data];
          for (; t != null && t.parent; )
            o.push(t.parent.data), t = t.parent;
          const x = o.reverse().map((V) => V.id), S = `${n.parent.data.name}.${n.data.name}`;
          g.length = 0, g.push(...x), c.emit("up:database", o[0]), c.emit("up:ids", x), c.emit("up:name", S, o);
        };
        return m.value && W(m.value), de(m, (n, t) => {
          W(n), t != null && (g.length = 0, c.emit("up:ids", []), c.emit("up:name", ""));
        }), () => D(ce, { modelValue: g, options: b, props: { ...p, lazyLoad: $ }, "onUpdate:modelValue": (n) => {
          console.log("------->", n);
        } }, {
          default: ({ data: n }) => D("div", { style: "display:flex;align-items:center;gap:.5em;", onClick: () => J(n) }, [
            D("img", { style: "height:1em;max-height:1em;", src: s(n.type), title: `${n.type} - ${n.label}` }),
            D("span", n.label)
          ])
        });
      }
    }), me = jt(() => {
      L("change", d.value, e, i, _);
    }, 500);
    return (r, c) => {
      var m, N;
      return w(), j("div", zt, [
        M("div", St, [
          k(a(O), {
            class: "min-w-400",
            id: a(U),
            groups: a(H),
            "onUp:server": y,
            "onUp:id": c[0] || (c[0] = (g) => L("update:serverId", g))
          }, null, 8, ["id", "groups"]),
          k(a(ve), {
            class: "min-w-400",
            ids: a(A),
            server: d.value,
            "onUp:ids": c[1] || (c[1] = (g) => L("update:schemaIds", g)),
            "onUp:database": ge,
            "onUp:name": f
          }, null, 8, ["ids", "server"]),
          M("div", null, [
            a(I) != null ? (w(), te(a(le), {
              key: 0,
              loading: v.value,
              icon: u[(m = d.value) == null ? void 0 : m.id] == !0 ? a(Lt) : a(Pt),
              type: u[(N = d.value) == null ? void 0 : N.id] == !0 ? "success" : "primary",
              onClick: z
            }, {
              default: F(() => {
                var g;
                return [
                  ne(Dt(u[(g = d.value) == null ? void 0 : g.id] == !0 ? "重新测试" : "测试连接"), 1)
                ];
              }),
              _: 1
            }, 8, ["loading", "icon", "type"])) : Ft("", !0)
          ])
        ])
      ]);
    };
  }
}), Mt = {
  class: "comp-fields",
  flex: "",
  "w-full": "",
  "gap-20": "",
  "overflow-auto": ""
}, Rt = {
  "flex-1": "",
  class: "max-w-40% min-w-30%"
}, Gt = { "min-w-50": "" }, At = /* @__PURE__ */ M("div", { "h-50": "" }, null, -1), Ht = {
  "h-48": "",
  flex: "",
  "items-center": "",
  "justify-center": ""
}, Jt = {
  key: 0,
  class: "i-mingcute:arrow-right-fill w-2em h-2em c-#409EFF"
}, Kt = {
  key: 1,
  class: "i-nimbus:stop w-2em h-2em c-#ddd"
}, Qt = {
  "flex-2": "",
  "w-full": ""
}, Wt = /* @__PURE__ */ ee({
  __name: "fileds",
  props: {
    inputFileds: { default: "" },
    inputProps: { default: () => ({}) },
    outputFileds: { default: "" },
    outputProps: { default: () => ({}) },
    formdata: {},
    data: {}
  },
  emits: ["change", "update:data"],
  setup(C, { emit: R }) {
    const q = C, { inputProps: E, outputProps: G, formdata: U, outputFileds: A, inputFileds: H, data: I = [] } = q, L = R, P = Z(() => h(U, H) || []), l = Z(() => h(U, A) || []), s = Z(() => {
      const e = Object.assign({ name: "name", type: "type", remark: "remark", main: "main", isNull: "isNull", label: "name", value: "name" }, G || {});
      return a(l).map((i) => ({ label: h(i, e.label) || h(i, e.value), value: h(i, e.value), name: h(i, e.name) || h(i, e.value), type: h(i, e.type), remark: h(i, e.remark) })) || [];
    }), v = Z(() => {
      const e = Object.assign({ name: "name", type: "type", remark: "remark" }, E || {});
      return a(P).map((i) => ({ name: h(i, e.name), type: h(i, e.type), remark: h(i, e.remark) }));
    }), u = ie(I), d = () => {
      const e = [];
      for (const i of a(v)) {
        const _ = a(s).find((f) => f.name == i.name);
        _ ? e.push({ ..._ }) : e.push({});
      }
      u.value = e;
    };
    de([P, l], ([e, i]) => {
      d(), i.length > 0 && e.length > 0 && O();
    });
    const y = (e, i) => {
      const _ = a(s).find((f) => f.value == e);
      _ && Object.assign(i.row, _), O();
    }, z = (e, i) => {
      e.row.$enabled = i, O();
    }, O = () => {
      if (a(u).length > 0) {
        const e = a(u).map((i, _) => i.$enabled == !1 ? void 0 : [v.value[_], { ...i }]).filter((i) => i != null);
        L("change", e), L("update:data", a(u));
      }
    };
    return It(() => {
      I.length != a(P).length && d();
    }), (e, i) => (w(), j("div", Mt, [
      M("div", Rt, [
        k(a(pe), {
          data: v.value,
          "row-style": { height: "48px", "box-sizing": "border-box" },
          "header-row-style": { height: "50px", "box-sizing": "border-box" }
        }, {
          default: F(() => [
            k(a(B), {
              label: "输入表字段",
              prop: "name"
            }),
            k(a(B), {
              label: "类型",
              prop: "type",
              width: "120"
            })
          ]),
          _: 1
        }, 8, ["data"])
      ]),
      M("div", Gt, [
        At,
        (w(!0), j(oe, null, _e(u.value, (_) => (w(), j("div", Ht, [
          _.$enabled != !1 ? (w(), j("div", Jt)) : (w(), j("div", Kt))
        ]))), 256))
      ]),
      M("div", Qt, [
        k(a(pe), {
          data: u.value,
          "row-style": { height: "48px", "box-sizing": "border-box" },
          "header-row-style": { height: "50px", "box-sizing": "border-box" }
        }, {
          default: F(() => [
            k(a(B), {
              label: "目标表字段",
              prop: "name"
            }, {
              default: F((_) => [
                k(a(se), {
                  modelValue: _.row.name,
                  "onUpdate:modelValue": (f) => _.row.name = f,
                  disabled: _.row.$enabled == !1,
                  onChange: (f) => y(f, _),
                  size: "small"
                }, {
                  default: F(() => [
                    (w(!0), j(oe, null, _e(s.value, (f) => (w(), te(a(qt), {
                      label: f.label,
                      value: f.value
                    }, null, 8, ["label", "value"]))), 256))
                  ]),
                  _: 2
                }, 1032, ["modelValue", "onUpdate:modelValue", "disabled", "onChange"])
              ]),
              _: 1
            }),
            k(a(B), {
              label: "类型",
              prop: "type",
              width: "120"
            }),
            k(a(B), {
              label: "主键",
              prop: "main",
              width: "80"
            }),
            k(a(B), {
              label: "操作",
              width: "120"
            }, {
              default: F((_) => [
                _.row.$enabled != !1 ? (w(), te(a(le), {
                  key: 0,
                  size: "small",
                  onClick: re(() => z(_, !1), ["stop"])
                }, {
                  default: F(() => [
                    ne("删除")
                  ]),
                  _: 2
                }, 1032, ["onClick"])) : (w(), te(a(le), {
                  key: 1,
                  size: "small",
                  onClick: re(() => z(_, !0), ["stop"])
                }, {
                  default: F(() => [
                    ne("恢复")
                  ]),
                  _: 2
                }, 1032, ["onClick"]))
              ]),
              _: 1
            })
          ]),
          _: 1
        }, 8, ["data"])
      ])
    ]));
  }
}), ia = (C) => {
  const R = "TableOutput", q = {
    // ports: { items: [{ "id": "in", "group": "left" }, { "id": "out", "group": "right" }] },
    ports: { items: [{ id: "in", group: "left" }] }
  }, E = async (l, s) => {
    const [v] = C.util.createConnectionData(l, s);
    return await C.api.testConnect({ connection: v });
  }, G = (l, s) => {
    console.log(s, l);
  }, U = { name: "表输出", $truncate: "over", type: "TableOutput", description: [], distribute: "N", custom_distribution: [], copies: "1", partitioning: { method: "none", schema_name: [] }, connection: "", schema: "", table: "", commit: "1000", truncate: "N", ignore_errors: "Y", use_batch: "Y", specify_fields: "Y", partitioning_enabled: "N", partitioning_field: "", partitioning_daily: "N", partitioning_monthly: "Y", tablename_in_field: "N", tablename_field: "", tablename_in_table: "N", return_keys: "N", return_field: "", fields: { field: [] }, attributes: "", cluster_schema: "", remotesteps: { input: "", output: "" }, GUI: { xloc: 448, yloc: 160, draw: "Y" } }, A = async (l, s) => {
    const [v, u, d, y] = s;
    if (console.log("initFields ====> ", s, u, d, y), !v) {
      ue.warning("请选择数据源");
      return;
    }
    if (!u || !d) {
      ue.warning("请选择数据表");
      return;
    }
    y && y[1] && K(l, "schema", y[1].name), y && y[2] && K(l, "table", y[2].name);
    const [z, O] = C.util.createConnectionData(v, u);
    K(l, "connection", O);
    const e = await C.api.getFieldInfo({ connectionDetailVO: { connection: z }, querySql: d });
    e && K(l, "$fields", e);
  }, H = (l, s) => {
    if (s && s.length > 0) {
      const v = s.map(([u, d]) => ({ stream_name: u.name, column_name: d.name }));
      K(l, "fields", { field: v });
    }
  };
  return { name: R, step: U, markup: q, tabs: [
    { default: !0, type: "form", label: "属性配置", column: [
      { tag: Bt, "v-model:serverId": "formData.$serverId", "v-model:schemaIds": "formData.$tableIds", "@change": ({ formData: l, $: s }) => A(l, s), testConnect: E },
      { tag: ae },
      { tag: Et, label: "数据入表方式", prop: "$truncate", tip: { content: `
  <p>清空覆盖：删除表数据后再插入新数据</p>
  <p>追加：将数据直接追加到表中，如果遇到主键（唯一约束）冲突，则直接报错并结束</p>
  <p>插入且更新：将数据追加到表中，遇到主键冲突时覆盖这条数据</p>
  <p>插入不更新：只追加不同主键的数据，相同主键的数据直接舍弃</p>
  `, rawContent: !0 }, "@change": ({ formData: l, $: s }) => G(l, s[0]), cls: [{ cls: "清空覆盖", value: "over" }, { cls: "追加", value: "insert" }, { cls: "插入且更新", value: "update" }, { cls: "插入不更新", value: "add" }] },
      { tag: ae },
      { tag: Wt, "v-model:data": "formData.$fieldsOutData", ":formdata": "formData", outputFileds: "$fields", inputFileds: "outFields", outputProps: { value: "fieldName", type: "fieldType" }, "@change": ({ formData: l, $: s }) => H(l, s[0]) }
    ] },
    { type: "form", label: "高级配置", column: [
      { label: "提交记录数量", prop: "commit" },
      { label: "裁剪表", tag: T, prop: "truncate", activeValue: "Y", inactiveValue: "N", inlinePrompt: !0, activeText: "Y", inactiveText: "N" },
      { label: "忽略插入错误", tag: T, prop: "ignore_errors", activeValue: "Y", inactiveValue: "N", inlinePrompt: !0, activeText: "Y", inactiveText: "N" },
      { label: "指定数据可字段", tag: T, prop: "specify_fields", activeValue: "Y", inactiveValue: "N", inlinePrompt: !0, activeText: "Y", inactiveText: "N" },
      // {prop:"",label:"",tag:ElSwitch,trueLabel:"Y",falseLabel:"N"}
      { tag: ae, cls: "主选项" },
      { label: "表分区数据", tag: T, prop: "partitioning_enabled", activeValue: "Y", inactiveValue: "N", inlinePrompt: !0, activeText: "Y", inactiveText: "N" },
      { label: "分区字段", tag: se, prop: "partitioning_field", cls: [] },
      //  item in step.outFields
      { label: "每月分区数据", tag: T, prop: "partitioning_daily", ":disabled": "formData['partitioning_enabled'] == 'N'", activeValue: "Y", inactiveValue: "N", inlinePrompt: !0, activeText: "Y", inactiveText: "N" },
      { label: "每天分区数据", tag: T, prop: "partitioning_monthly", ":disabled": "formData['partitioning_enabled'] == 'N'", activeValue: "Y", inactiveValue: "N", inlinePrompt: !0, activeText: "Y", inactiveText: "N" },
      { label: "使用批量插入", tag: T, prop: "use_batch", ":disabled": "formData['return_keys'] == true", activeValue: "Y", inactiveValue: "N", inlinePrompt: !0, activeText: "Y", inactiveText: "N" },
      { label: "表名定义在一个字段里", tag: T, prop: "tablename_in_field", activeValue: "Y", inactiveValue: "N", inlinePrompt: !0, activeText: "Y", inactiveText: "N" },
      { label: "包含表名的字段", tag: se, prop: "tablename_field", clearable: !0, ":disabled": "formData['tablename_in_field'] == 'N'", cls: [] },
      { label: "存储表名字段", tag: T, prop: "tablename_in_table", ":disabled": "formData['tablename_in_field'] == 'N'", activeValue: "Y", inactiveValue: "N", inlinePrompt: !0, activeText: "Y", inactiveText: "N" },
      { label: "返回一个自动产生的关键字", tag: T, prop: "return_keys", activeValue: "Y", inactiveValue: "N", inlinePrompt: !0, activeText: "Y", inactiveText: "N" },
      { label: "自动产生关键字的名称", prop: "return_field", ":disabled": "formData['return_keys'] == 'N'" }
    ] }
  ], metadata: {} };
};
export {
  ia as default
};
